package pbl;

import java.net.*;
import java.io.*;

/**
 * @author AMPM
 * 
 * This class represents a simple TCP client able to connect to
 * and communicate with a simple TCP server.
 *
 */

public class SimpleTcpClient {
	
  public static void main (String args[]) throws Exception{
	// an object representing this computers IP address
    InetAddress serverAddress = InetAddress.getByName("localhost");
    int serverPort = 7896;
    
    // the String and Boolean objects below are the data we want to send
    String message = "Shut up and calculate!";
    Boolean toUpperCase = true;
    
    // we request to establish a socket connection to a remote server
    Socket socket = new Socket( serverAddress, serverPort ); // Mark IP: "10.25.231.232"
    
    // get the output stream from the socket
    OutputStream os = socket.getOutputStream();
    // wrap it in the ObjectOutputStream object
    ObjectOutputStream oos = new ObjectOutputStream( os );
    
    // the data for sending is written to the (wrapped) output stream
    oos.writeObject(toUpperCase);
    oos.writeObject( message );
    
    // get the input stream from the socket
    InputStream is = socket.getInputStream();
    // wrap it in the ObjectOutputStream object
    ObjectInputStream ois = new ObjectInputStream( is );
    
    // get the response from the server and cast it to a String object
    String response = (String) ois.readObject();
    
    System.out.println( response );
    
	socket.close();
  }	
}